//
//  EditTextController.m
//  iStage
//
//  Created by michael on 24/07/2008.
//  Copyright 2008 Legal Education Technology Lab. All rights reserved.
//

#import "EditTextController.h"
#import "DataManager.h"

@implementation EditTextController
@synthesize label,valueName, valueField,navigation,value;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
	if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
		// Initialization code
		valueField = [[UITextField alloc] initWithFrame:CGRectZero];
		valueField.keyboardType=UIKeyboardTypeDefault;
		valueField.autocorrectionType= YES;
		valueField.autocapitalizationType= UITextAutocapitalizationTypeWords;
	}
	return self;
}
-(IBAction)doneEditing{
	//should probably be done by KV-coding
	NSLog(@"Value is ");
	NSLog(valueField.text);
	[[[DataManager sharedDataManager] currentProduction] setObject:valueField.text forKey:valueName];
	if ([self parentViewController] == nil) {
		NSLog(@"Parent View Controller is nil");
	}
	else {
		//NSLog([self parentViewController] );
//		[[self parentViewController] 
		
		
	}
//	[self dismissModalViewControllerAnimated:YES];	
	[self dismissModalViewControllerAnimated:YES];//[self cancelEditing];
}
-(IBAction)cancelEditing{
	[self dismissModalViewControllerAnimated:YES];
}
/*
 Implement loadView if you want to create a view hierarchy programmatically
- (void)loadView {
}
 */

/*
 If you need to do additional setup after loading the view, override viewDidLoad.
- (void)viewDidLoad {
}
 */
-(void)viewWillAppear:(BOOL)animated {

}


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
	// Return YES for supported orientations
	return (interfaceOrientation == UIInterfaceOrientationPortrait);
}


- (void)didReceiveMemoryWarning {
	[super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
	// Release anything that's not essential, such as cached data
}


- (void)dealloc {
	[super dealloc];
}

-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
	return YES;
}
- (void)textFieldDidBeginEditing:(UITextField *)textField {

}

-(void)viewDidLoad {
	/* text field data is not appearing text box */
	//noOfPostsTextField.text = [[dm currentBlog] valueForKey:kPostsDownloadCount];
	valueField.text= [[DataManager sharedDataManager].currentProduction valueForKey:self.valueName];
//	valueField.text = self.value;
	NSLog(@"view did load with value:");
	NSLog(valueField.text);
	[valueField becomeFirstResponder];
}

@end
